<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<body>
<script>
test(function(t) {
    var canvas = document.createElement('canvas');
    var ctx = canvas.getContext('2d');

    ctx.clearRect(0, 0, canvas.width, canvas.height);
    ctx.beginPath();
    var p1 = new Path2D();
    p1.rect(0,0,100,100);
    var p2 = new Path2D();
    p2.rect(0,100,100,100);
    var m = new DOMMatrix();
    p1.addPath(p2, m);
    ctx.fillStyle = 'yellow';
    ctx.fill(p1);
    assert_array_equals(ctx.getImageData(1, 100, 1, 1).data, [255, 255, 0, 255]);

    ctx.clearRect(0, 0, canvas.width, canvas.height);
    ctx.beginPath();
    var p3 = new Path2D();
    p3.rect(0,0,100,100);
    var p4 = new Path2D();
    p4.rect(0,100,100,100);
    m.a = 1; m.b = 0;
    m.c = 0; m.d = 1;
    m.e = 100; m.f = -100;
    p3.addPath(p4, m);
    ctx.fillStyle = 'yellow';
    ctx.fill(p3);
    assert_array_equals(ctx.getImageData(101, 0, 1, 1).data, [255, 255, 0, 255]);

    ctx.clearRect(0, 0, canvas.width, canvas.height);
    ctx.beginPath();
    var p5 = new Path2D();
    p5.rect(0,0,100,100);
    var p6 = new Path2D();
    p6.rect(100,100,100,100);
    m.a = 0; m.b = 0;
    m.c = 0; m.d = 0;
    m.e = 0; m.f = 0;
    p5.addPath(p6, m);
    ctx.fillStyle = 'yellow';
    ctx.fill(p5);
    assert_array_equals(ctx.getImageData(101, 100, 1, 1).data, [0, 0, 0, 0]);

    ctx.clearRect(0, 0, canvas.width, canvas.height);
    ctx.beginPath();
    var p7 = new Path2D();
    p7.rect(0,0,100,100);
    var p8 = new Path2D();
    p8.rect(100,100,100,100);
    p7.addPath(p8, null);
    p7.addPath(p8, []);
    p7.addPath(p8, {});
    ctx.fillStyle = 'red';
    ctx.fill(p7);
    assert_array_equals(ctx.getImageData(101, 100, 1, 1).data, [255, 0, 0, 255]);

    ctx.clearRect(0, 0, canvas.width, canvas.height);
    ctx.beginPath();
    var p9 = new Path2D();
    var p10 = new Path2D();
    p9.rect(0,0,10,10);
    p10.addPath(p9);
    ctx.fillStyle = 'red';
    ctx.fill(p10);
    assert_array_equals(ctx.getImageData(1, 1, 1, 1).data, [255, 0, 0, 255]);

    var p9 = new Path2D();
    p9.rect(0,0,100,100);
    assert_throws_js(TypeError, function() {
      p7.addPath(null, m);
    });
    assert_throws_js(TypeError, function() {
      p7.addPath([], m);
    });
    assert_throws_js(TypeError, function() {
      p7.addPath({}, m);
    });
}, "Test addPath() method.");
</script>
</body>
